import java.io.DataInputStream;
import java.io.DataOutputStream;
import javax.microedition.io.SocketConnection;
import net.dclausen.microfloat.MicroDouble;
/*
 * Value.java
 *
 * Created on January 31, 2006, 1:09 PM
 *
 * Custom data structure represents an entry in symbole table. Holds a possible
 * variable value of double, string, boolean, or object. For I/O, data streams
 * are saved also.
 */

/**
 *
 * @author Administrator
 */
public class Value {
    
    public long dVal = 0; // simulation of double
    public String sVal = null; // string
    public boolean bVal = false; // boolean
    public Object oVal = null; // object: generic
    public short type = 0; // type of current entry
    public DataInputStream dis = null; // I/O streams
    public DataOutputStream dos = null;
    
    public static final short NUM = 101; // types of current entry
    public static final short TXT = 102;
    public static final short BOL = 103;
    public static final short OBJ = 104;
    
    /** Convert value to string for printing */
    public String toString() {
        if (type == NUM) { return MicroDouble.toString(dVal); }
        if (type == TXT) { return sVal; }
        if (type == BOL) { return String.valueOf(bVal); }
        if (type == OBJ) { return String.valueOf(oVal); }
        return null;
    }
    
    /** Creates a new instance of Value */
    public Value() {
    }
    
    /** Creates a new instance of Value of type object */
    public Value(Object o) {
        oVal = o;
        type = OBJ;
    }
    
    /** Creates a new instance of Value of type string */
    public Value(String s) {
        sVal = s;
        type = TXT;
    }
    
    /** Creates a new instance of Value of type double */
    public Value(long d) {
        dVal = d;
        type = NUM;
    }
    
    /** Creates a new instance of Value of type socket */
    public Value(SocketConnection sc) {
        type = OBJ;
        oVal = sc;
        try {
            dis = sc.openDataInputStream();
            dos = sc.openDataOutputStream();
        } catch (Exception e) {}
    }
}
